package com.book.controller.book;

import com.book.core.domain.BookCategories;
import com.book.core.mode.R;
import com.book.core.vo.BookCategoryVO;
import com.book.service.BookCategoriesService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/book/category")
public class BookCategoryController {
    private final BookCategoriesService bookCategoriesService;

    @PostMapping
    @PreAuthorize("hasAuthority('book:category:create')")
    public R<String> createBookCategory(@RequestBody @Validated BookCategories bookCategories) {
        bookCategoriesService.createBookCategory(bookCategories);
        return R.ok("新增成功",null);
    }

    @GetMapping("/tree-list")
    public R<List<BookCategoryVO>> getTreeList() {
        return R.ok(bookCategoriesService.getTreeList());
    }
    @PutMapping
    public R<String> updateBookCategory(@RequestBody @Validated BookCategories bookCategories) {
        bookCategoriesService.updateById(bookCategories);
        return R.ok("修改成功",null);
    }
}
